package csvm_v2.components;

import csvm_v1.coins.Dime;
import csvm_v1.coins.Nickel;
import csvm_v1.coins.Quarter;

/**
 * CoinReceiver bertugas untuk menerima koin yang dimasukkan oleh pengguna
 * sebelum digunakan untuk transaksi
 *
 * @author Muqtafi Akhmad
 */
public class CoinReceiver extends CoinContainer {

    /**
     * konstruktor default dari CoinReceiver
     */
    public CoinReceiver() {
        super();
    }

    /**
     * konstruktor berparameter dari CoinReceiver
     *
     * @param dimeCount jumlah dime
     * @param nickelCount jumlah nickel
     * @param quarterCount jumlah quarter
     */
    public CoinReceiver(Integer dimeCount, Integer nickelCount, Integer quarterCount) {
        super(dimeCount, nickelCount, quarterCount);
    }

    /**
     * menambahkan koin ke dalam koleksi dari container
     *
     * @param size ukuran koin
     * @param weight berat koin
     * @param thickness ketebalan coin
     * @param isSerratedEdge keterangan apakah koin bergerigi
     */
    public void inputCoin(float size, float weight, float thickness, boolean isSerratedEdge) {
        this.grabResource();
        if (Dime.isDime(size, weight, thickness, isSerratedEdge)) {
            dimeCount++;
        } else if (Nickel.isNickel(size, weight, thickness, isSerratedEdge)) {
            nickelCount++;
        } else if (Quarter.isQuarter(size, weight, thickness, isSerratedEdge)) {
            quarterCount++;
        } else {
            System.out.println("slug terdeteksi, input ditolak");
        }
        this.releaseResource();
    }
}
